// This Plugin use Vanish when in Combat and not on CD
// Then Waits for 5sec to combat to clear

using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Net;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading;
using System.Xml.Linq;
using Styx.TreeSharp;
using CommonBehaviors.Actions;
using Styx;
using Styx.WoWInternals;
using Styx.CommonBot.POI;
// HB Stuff
using Styx.Common;
using Styx.Common.Helpers;
using Styx.CommonBot;
using Styx.CommonBot.Inventory;
using Styx.Helpers;
using Styx.Plugins;
using Styx.WoWInternals.WoWObjects;

using System.Collections.Generic;

namespace Vanish
{
    public class Vanish : HBPlugin
    {
        #region Globals

        public override string Name { get { return "Vanish"; } }
        public override string Author { get { return "Wexy"; } }
        public override Version Version { get { return new Version(1, 0, 0, 1); } }
        public override bool WantButton { get { return false; } }
        private static LocalPlayer Me { get { return StyxWoW.Me; } }
        private int count = 0;
        private int stuckCount = 0;

        #endregion
        public override void Pulse()
        {	// CHECKs if Questing bot is run (This Vanish behaviour should only be used in PVE)
            if (BotManager.Current.Name.Equals("Questing") )
			{
			if (Me.Combat && !Me.HasAura("Vanish"))
                {
                    if (!SpellOnCooldown("Vanish")) 
					{
					// Turning off auto attacks
                    Lua.DoString("RunMacroText('/stopattack');");
					SpellManager.Cast("Cloak of Shadows");
					SpellManager.Cast("Vanish");
					SpellManager.Cast("Shadow Walk");
					StyxWoW.Me.ClearTarget(); 
					BotPoi.Clear();
					// Waiting for targets to clear
					Logging.Write("[Vanish]: Vanished lets continue!");
					WoWMovement.MoveStop();
					Me.ClearTarget();
					System.Threading.Thread.Sleep(2500);
					Logging.Write("Waited 2500 mili sec!");
					return;
					}
                }
			
			}
        }
		
	  private static bool SpellOnCooldown(string spell)
        {
            SpellFindResults results;
            if (SpellManager.FindSpell(spell, out results))
            {
                return results.Override != null ? results.Override.Cooldown : results.Original.Cooldown;
            }

            return false;
        }
    }

}
